<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('盲盒管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>盲盒名称：</label>
                                <input type="text" name="blindboxName"/>
                            </li>
                            <li>
                                <label>盲盒类型：</label>
                                <select name="type" th:with="type=${@dict.getType('box_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="lucky:blindbox:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="lucky:blindbox:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="lucky:blindbox:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="lucky:blindbox:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('lucky:blindbox:edit')}]];
        var removeFlag = [[${@permission.hasPermi('lucky:blindbox:remove')}]];
        var prefix = ctx + "lucky/blindbox";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "盲盒管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'blindboxId',
                    title: '盲盒ID',
                    visible: false
                },
                {
                    field: 'blindboxName',
                    title: '盲盒名称'
                },
                {
                    field: 'type',
                    title: '盲盒类型',
                    formatter: function (value, row, index) {
                        if(value ==0){
                            return  '每日'
                        }else{
                            return  '普通'
                        }
                    }
                },
                // {
                //     field: 'costfee',
                //     title: '成本价格'
                // },
                {
                    field: 'sellfee',
                    title: '出售价格'
                },
                {
                    field: 'oncount',
                    title: '上架数量'
                },
                {
                    field: 'stockcount',
                    title: '库存数量'
                },
                {
                    field: 'status',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'failureTime',
                    title: '失效天数'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="setGoods(\'' + row.blindboxId + '\')"><i class="fa fa-edit"></i>商品管理</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 盲盒状态显示 */
        function statusTools(row) {
            if (row.status == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.blindboxId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.blindboxId + '\')"></i> ';
            }
        }
        /* 盲盒-停用 */
        function disable(blindboxId) {
            $.modal.confirm("确认要冻结该盲盒吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "blindboxId": blindboxId, "status": 1 });
            })
        }

        /* 盲盒启用 */
        function enable(blindboxId) {
            $.modal.confirm("确认要激活该盲盒吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "blindboxId": blindboxId, "status": 0 });
            })
        }
        /*商品添加*/
        function setGoods(id, width, height){
            var _url = prefix + "/setGoods?blindboxId="+id;
            var _width = $.common.isEmpty(width) ? "800" : width;
            var _height = $.common.isEmpty(height) ? ($(window).height() - 50) : height;
            //如果是移动端，就使用自适应大小弹窗
            if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                _width = 'auto';
                _height = 'auto';
            }
            layer.open({
                type: 2,
                area: [_width + 'px', _height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: '商品管理',
                content: _url,
                btn: '关闭',
                // 弹层外区域关闭
                // shadeClose: true,
                success: function (layer) {
                    layer[0].childNodes[3].childNodes[0].attributes[0].value = 'layui-layer-btn1';
                },
                btn1: function (index) {
                    layer.close(index);
                }
            });
        }
    </script>
</body>
</html>